<?php

class Ead_ContatoController extends Ead_Controller_Action
{

    public function init()
    {
       
    }

    public function indexAction() {
        
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/validation/dist/jquery.validate.min.js');
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/ead/contato.js');
        
        $sessao = new Zend_Session_Namespace('Aluno');
        $this->view->aluno = $sessao->aluno;
        
        $query = 'SELECT SQL_CACHE PRS_ID,PRS_NOM FROM PROFESSOR WHERE PRS_STA = 1 ORDER BY PRS_NOM';
        $result = $this->db->fetchAll($query);
        $this->view->professor = $result;
        
        if($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            
            $data = array(
                'PRS_ID' => $formData['professor'],
                'ALU_ID' => $sessao->aluno['ALU_ID'],
                'CON_AST' => $formData['assunto'],
                'CON_TXT' => $formData['mensagem'],
                'CON_DATHOR' => date('Y-m-d H:i:s'),
            );
            
            $this->db->insert('EAD_CONTATO',$data);
            
            echo '<script>alert("Mensagem enviada com sucesso!");</script>';
        }
    }
    
    
}